package io.ray.study.mockito.service.impl;

import io.ray.study.mockito.pojo.Good;
import io.ray.study.mockito.pojo.OrderCreatePojo;
import io.ray.study.mockito.service.OrderService;
import io.ray.study.mockito.service.ServiceException;
import io.ray.study.mockito.service.UserService;
import io.ray.study.mockito.service.WarehouseService;

public class OrderServiceImpl implements OrderService {

	private UserService userService;

	private WarehouseService warehouseService;

	@Override
	public void createOrder(OrderCreatePojo pojo) {

		if (!userService.userExisted(pojo.getUser().getId()))
			throw new ServiceException();

		for (Good good : pojo.getItems()) {
			if (!warehouseService.hasGoodEnough(good.getSkuID(), good.getNum()))
				throw new ServiceException();
		}

		System.out.println("Create Order");
	}

}
